import request from '@/utils/request';
import { AnalysisData } from './data.d';
import { TableListItem } from '../../Plan/data.d';


//统计数量:设备数, 节目数, 计划数
export async function statisticsTotalCount() {
  return request('/api/index/statisticsTotalCount', {
    method: 'GET',
    headers: {
      Authorization: localStorage.getItem('token'),
    },
  })
}

//设备状态统计
export async function statisticsDeviceStatus() {
  return request('/api/index/statisticsDeviceStatus', {
    method: 'GET',
    headers: {
      Authorization: localStorage.getItem('token'),
    },
  })
}
//设备分布统计
export async function statisticsOrgDevice(params:any) {
  return request('/api/index/statisticsOrgDevice', {
    method: 'GET',
    headers: {
      Authorization: localStorage.getItem('token'),
    },
    params,
  })
}
//素材资源统计
export async function statisticsMaterialResource() {
  return request('/api/index/statisticsMaterialResource', {
    method: 'GET',
    headers: {
      Authorization: localStorage.getItem('token'),
    },
  })
}
//计划状态统计
export async function statisticsPlanStatus() {
  return request('/api/index/statisticsPlanStatus', {
    method: 'GET',
    headers: {
      Authorization: localStorage.getItem('token'),
    },
  })
}

const getRandomuserParams = (params: any) => {
  return {
    pageSize: params.pageSize,
    pageNo: params.current,
    ...params,
  };
};

//计划列表/计划审核列表
export async function planList(params: TableListItem) {
  params = getRandomuserParams(params);
  return request('/api/index/planList', {
    method: 'GET',
    headers: {
      Authorization: localStorage.getItem('token'),
    },
    params,
  }).then((response) => {
    if (response && response.code === 200) {
      //数据转换
      const obj = new Object();
      let list = response.data.list;
      for (var i in list) {
        list[i].index = parseInt(i)+1;//序号
        list[i].key = list[i].id;
      }
      obj['data'] = list;
      obj['pageCount'] = response.data.pageCount;
      obj['current'] = response.data.pageNo;
      obj['total'] = response.data.totalCount;
      return obj;
    }
  });
}

const getFakeChartData: AnalysisData = {};

export default {
  // 'GET  /api/chart_data': getFakeChartData,
};


export async function fakeChartData() {
  // return request('/api/chart_data');
  getFakeChartData
}


